﻿using LineOfBusiness.Controls.Base;
using LineOfBusiness.DataAccess;
using LineOfBusiness.Poco;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace LineOfBusiness.AD.Controllers
{
    public class UserAccountPolicyController : LOBController
    {
        public UserAccountPolicyController()
        {
            this.GridViewName = "grvtblUserAccountPolicy";
        }

        public ActionResult Index()
        {
            using (EFDALContainer dal = new EFDALContainer())
            {
                AD_tblUserAccountPolicy UserAccountPolicy = dal.Repository.GetQuery<AD_tblUserAccountPolicy>().FirstOrDefault();
                if (UserAccountPolicy == null) UserAccountPolicy = new AD_tblUserAccountPolicy() { ID = Guid.NewGuid() };
                return View(UserAccountPolicy);
            }
            
        }

        [HttpPost]
        public ActionResult Save(AD_tblUserAccountPolicy UserAccountPolicy)
        {
            using (EFDALContainer dal = new EFDALContainer())
            {
                try
                {
                    dal.Repository.AddOrUpdate(UserAccountPolicy);
                    dal.UnitOfWork.SaveChanges();
                }
                catch (Exception exp)
                {
                    return Json(exp.Message);
                }
                return Json("0");
            }
        }
    }
}
